<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <jsp:include page="../incHead.jsp">
        <jsp:param name="title" value="picker.title" />
    </jsp:include>
    <body>        
        <jsp:include page="../incHeader.jsp"/>
        <div id="container">
            <jsp:include page="../incMenu.jsp"/>
            <div id="content">         
                <div class="divOfForms">
                    <sec:authorize access="hasRole('ROLE_ADMIN')">
                    <div id="title_subsection">
                        <h3><fmt:message key="picker.title"/></h3>
                    </div>
                    </sec:authorize>
                    <div id="content_subsection">
                        <sec:authorize access="hasRole('ROLE_ADMIN')">
                        <form:form action="addPicker" method="POST">
                            <table class="tableOfForms">
                                <tr>
                                    <td class="outputInTable"><form:label path="firstName"><fmt:message key="picker.name"/></form:label></td>
                                    <td><form:input path="firstName" /></td>
                                    <td><form:errors class="error" path="firstName" /></td>
                                </tr>
                                <tr>
                                    <td class="outputInTable"><form:label path="lastName"><fmt:message key="picker.surname"/></form:label></td>
                                    <td><form:input path="lastName" /></td>
                                    <td><form:errors class="error" path="lastName" /></td>
                                </tr>
                                <tr>
                                    <td class="outputInTable"><form:label path="nickName"><fmt:message key="picker.nickname"/></form:label></td>
                                    <td><form:input path="nickName" /></td>
                                    <td><form:errors class="error" path="nickName" /></td>
                                </tr>
                                <tr>
                                    <td class="outputInTable"><form:label path="password"><fmt:message key="picker.password"/></form:label></td>
                                    <td><form:input type="password" path="password" /></td>
                                    <td><form:errors class="error" path="password" /></td>
                                </tr>
                                <tr>
                                    <td class="outputInTable"><form:label path="pickerInfo"><fmt:message key="picker.info"/></form:label></td>
                                    <td><form:input path="pickerInfo" /></td>
                                    <td><form:errors class="error" path="pickerInfo" /></td>
                                </tr>
                                <tr>
                                    <td></td>
                                    <td><input type="submit" value=<fmt:message key="general.submit"/> /></td>
                                    <td></td>
                                </tr>
                            </table>
                        </form:form>
                        </sec:authorize>
                    </div>
                </div>
                <p class="error">${error}</p>
                <br/>
                <div class="divOfItems">
                    <div id="title_subsection">
                        <h3><fmt:message key="picker.all"/></h3>
                    </div>
                    <table class="allTable">
                        <th><fmt:message key="picker.name"/></th>
                        <th><fmt:message key="picker.surname"/></th>
                        <th><fmt:message key="picker.nickname"/></th>
                        <th><fmt:message key="picker.userRole"/></th>
                        <th><fmt:message key="picker.info"/></th>
                        <sec:authorize access="hasRole('ROLE_ADMIN')">
                        <th colspan="2"><fmt:message key="general.action"/></th>
                        </sec:authorize>
                        <c:forEach var="picker" items="${pickers}" >
                            <tr>
                                <td><c:out value="${picker.firstName}" /></td>
                                <td><c:out value="${picker.lastName}" /></td>
                                <td><c:out value="${picker.nickName}" /></td>
                                <td><fmt:message key="${picker.userRole}"/></td>
                                <td><c:out value="${picker.pickerInfo}" /></td>
                                <sec:authorize access="hasRole('ROLE_ADMIN')">
                                <td><a href="editPicker?id=${picker.id}"><fmt:message key="general.edit"/></a></td>
                                <td><a href="removePicker?id=${picker.id}" 
                                       onclick="return confirm('Are you sure you want to delete ${picker.nickName}?')">
                                        <fmt:message key="general.remove"/></a></td>
                                </sec:authorize>
                            </tr>
                        </c:forEach>
                    </table>    
                </div>    
            </div>
        </div>
    </body>
</html>